package com.zzyl.mapper;

import cn.hutool.core.date.DateTime;
import com.github.pagehelper.Page;
import com.zzyl.entity.Visit;
import com.zzyl.vo.VisitVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface ReservationMapper {

    /**
     * 查询每个时间段剩余预约次数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @MapKey("time")
    List<Map<String, Object>> countReservationByTime(DateTime startTime, DateTime endTime);

    /**
     * 新增预约
     *
     * @param visit
     */
    void insertReservation(Visit visit);

    /**
     * 分页查询预约
     *
     * @param status
     * @return
     */
    Page<VisitVo> pageReservations(Integer status, Long userId);

    /**
     * 取消预约
     *
     * @param id
     */
    void updateReservationStatus(Long id, Long userId);

    /**
     * 查询取消预约数量
     *
     * @param userId
     * @return
     */
    Integer countCancelReservation(@Param("userId") Long userId, @Param("time") LocalDate time);

    /**
     * 批量更改预约过期状态
     *
     * @param time
     */
    void updateReservationStatusByTime(LocalDateTime time);

    /**
     * 查询当前手机号是否预约当前时间
     *
     * @param time
     * @param mobile
     * @return
     */
    VisitVo isTimeAlreadyReservatedByPhone(@Param("time") LocalDateTime time, @Param("mobile") String mobile);
}
